﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniFramework.Event;
using YooAsset;

public partial class Boot : MonoBehaviour
{
#if ODIN_INSPECTOR
    [Sirenix.OdinInspector.Title("YooAsset Settings",TitleAlignment = Sirenix.OdinInspector.TitleAlignments.Centered)]
#else 
    [Header("YooAsset Settings")]
#endif
    [Tooltip("bundle资源服务器地址")]
    public string hostServerIP = "http://127.0.0.1:8000";
    [Tooltip("app版本")]
    public string appVersion = "v1.0";
    [Tooltip("资源系统运行模式")]
    public EPlayMode PlayMode = EPlayMode.EditorSimulateMode;

    // void Awake()
    // {
    //     Debug.Log($"资源系统运行模式：{PlayMode}");
    //     Application.targetFrameRate = 60;
    //     Application.runInBackground = true;
    //     DontDestroyOnLoad(this.gameObject);
    // }
    IEnumerator StartYooAsset()
    {
        // 游戏管理器
        // GameManager.Instance.Behaviour = this;

        // 初始化事件系统
        UniEvent.Initalize();

        // 初始化资源系统
        YooAssets.Initialize();

        // 加载更新页面
        var go = Resources.Load<GameObject>("PatchWindow");
        GameObject.Instantiate(go);

        // 开始补丁更新流程
        var operation = new PatchOperation("DefaultPackage", PlayMode);
        YooAssets.StartOperation(operation);
        yield return operation;

        // 设置默认的资源包
        var gamePackage = YooAssets.GetPackage("DefaultPackage");
        YooAssets.SetDefaultPackage(gamePackage);

        // 切换到主页面场景
        SceneEventDefine.ChangeToHomeScene.SendEventMessage();
    }
}